package org.lanqiao.service.Impl;

import org.lanqiao.dao.AdminDao;
import org.lanqiao.dao.Impl.AdminDaoImpl;
import org.lanqiao.entity.Admin;
import org.lanqiao.service.AdminService;

import java.util.List;

public class AdminServiceImpl implements AdminService {
    private AdminDao dao =new AdminDaoImpl();

    @Override
    public boolean addAdmin(Admin admin) {
        boolean flag=dao.isExistById(admin.getId());
        if (flag){
            System.out.println("此用户已经存在,不能添加");
            return false;
        }else {
            return dao.addAdmin(admin)==1?true:false;
        }
    }

    @Override
    public boolean delAdminById(Integer id) {
        boolean flag=dao.isExistById(id);
        if (flag){
            return dao.delAdmin(id)==1?true:false;
        }else {
            System.out.println("此用户不存在,无法删除");
            return false;
        }
    }

    @Override
    public boolean updAdmin(Admin admin) {
        boolean flag=dao.isExistById(admin.getId());
        if (flag){
            return dao.updAdmin(admin)==1?true:false;
        }else {
            System.out.println("此用户不存在,无法修改");
            return false;
        }
    }

    @Override
    public Admin findAdminById(Integer id) {
        return dao.findAdminById(id);
    }

    @Override
    public List<Admin> findAllAdmin() {
        return dao.findAllAdmins();
    }

    @Override
    public boolean isExistById(Integer id) {
        return dao.isExistById(id);
    }
}
